package com.itheima.controller;

import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.Blog;
import com.itheima.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("blog")
public class BlogController {
    @Autowired
    private BlogService blogService;

    /**
     * 增加博客
     * @param blogVo
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Map<String,Object> blogVo){
        blogService.add(blogVo);
        return new Result("success","操作成功！");
    }

    /**
     * 删除博客
     * @param blogVO
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Map<String,Object> blogVO){
        blogService.delete(blogVO);
        return new Result("success","操作成功");
    }

    /**
     * 删除选中博客
     * @param blogVoList
     * @return
     */
    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Map<String,Object>> blogVoList){
        blogService.deleteBatch(blogVoList);
        return new Result("success","操作成功");
    }

    /**
     * 编辑博客
     * @param blogVO
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Map<String,Object> blogVO){
        blogService.edit(blogVO);
        return new Result("success","操作成功");
    }

    @PostMapping("/getList")
    public Result getList(@RequestBody Map<String,Object> blogVO){
        PageResult<Blog> blogs = blogService.getList(blogVO);
        return new Result("success",blogs);
    }
}
